#include <Movement.h>

 const int AVG_CONST = 5;
 
 int RM_EN = 10;
 int LM_EN = 11;
 int LFWD = 13;
 int LREV = 12;
 int RFWD = 8;
 int RREV = 9;
 long int leftValue[AVG_CONST];
 long int rightValue[AVG_CONST];
 long int leftSum = 0;
 long int rightSum = 0;
 float leftAvg = 0.0;
 float rightAvg = 0.0;
 Movement mover(LFWD,LREV,RFWD,RREV,LM_EN,RM_EN);

void setup() {
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
}

void loop() {
  leftSum = 0;
  rightSum = 0;
  for(int i = 0; i<AVG_CONST; ++i)
  {
    leftValue[i] = analogRead(A1);
    rightValue[i] = analogRead(A0);
  }
  
  for(int i = 0; i<AVG_CONST; ++i)
  {
    leftSum += leftValue[i];
    rightSum += rightValue[i];
  }
  
  leftAvg = ((float)leftSum) / ((float)AVG_CONST);
  rightAvg = ((float)rightSum) / ((float)AVG_CONST);
  
  if((leftAvg - rightAvg) < -10.0)
  {
    mover.setMove(80,50);
    delay(1000);
  }
  else if((leftAvg - rightAvg) > 10.0)
  {
    mover.setMove(20,50);
    delay(1000);
  }
  else
    mover.setMove(50,50);
}
